package com.iplant.ams.service.po.dms.scada.status;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.ams.service.basicenum.dms.scada.DMSDeviceStatusEnum;
import com.iplant.base.utils.general.CalendarTool;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public class DMSDeviceStatusStatistics {
    /// <summary>
    /// 设备编码
    /// </summary>
    public String DeviceNo = "";


    public int DeviceID = 0;

    /// <summary>
    ///  设备名称
    /// </summary>
    public String DeviceName = "";

    /// <summary>
    /// 固定资产编码
    /// </summary>
    public String AssetNo = "";
    /// <summary>
    /// 设备型号ID
    /// </summary>
    public int ModelID = 0;
    /// <summary>
    /// 设备型号名称
    /// </summary>
    public String ModelName = "";
    /// <summary>
    /// 设备型号ID
    /// </summary>
    public String ModelNo = "";


    public String Remark = "";

    /// <summary>
    /// 设备类型编码
    /// </summary>
    public int DeviceType = 0;

    /// <summary>
    /// 设备类型名称
    /// </summary>
    public String DeviceTypeName = "";
    /// <summary>
    /// 设备类型编码
    /// </summary>
    public String DeviceTypeCode = "";

    public int AreaID = 0;

    public String AreaNo = "";
    /// <summary>
    /// 位置信息
    /// </summary>
    public String PositionText = "";

    public String ImageIcon = "";
    /// <summary>
    /// 当前状态
    /// </summary>
    public int Status = 0;

    /// <summary>
    /// 历史状态
    /// </summary>
    public int StatusHistory = 0;

    /// <summary>
    /// 状态改变时刻
    /// </summary>
    public Calendar StatusTime = CalendarTool.getCalendar(2000, 0, 1);

    /// <summary>
    /// 当前状态持续时长
    /// </summary>
    public int Duration = 0;


    public Map<String, Integer> StatusDurationDic = new HashMap<String, Integer>();


    public Map<String, Integer> StatusTimesDic = new HashMap<String, Integer>();

    /// <summary>
    /// 计划工作时长   工作日历的工作日*8小时
    /// </summary>
    public int PlanDuration = 0;

    /// <summary>
    /// 故障次数
    /// </summary>
    public int FailTimes = 0;


    /// <summary>
    /// 开机时长
    /// </summary>
    public int TurnOnDuration = 0;

    /// <summary>
    /// 关机时长
    /// </summary>
    public int TurnOffDuration = 0;

    /// <summary>
    /// 故障时长
    /// </summary>
    public int AlarmDuration = 0;


    /// <summary>
    /// 平均无故障时间  = 无故障时间/故障次数 =（开机时间-故障时间）/故障次数
    /// </summary>
    public int MTTF = 0;

    /// <summary>
    /// 平均故障间隔时间  = 开机时间/故障次数
    /// </summary>
    public int MTBF = 0;
    /// <summary>
    /// 平均修复时间   =  故障时间/故障次数
    /// </summary>
    public int MTTR = 0;


    public int RepairCount = 0;
    public int MaintainCount = 0;
    public double RepairDuration = 0;
    public double MaintainDuration = 0;

    public DMSDeviceStatusStatistics() {
    }

    public DMSDeviceStatusStatistics(DMSDeviceStatus wDMSDeviceStatus) {
        this.DeviceNo = wDMSDeviceStatus.DeviceNo;
        this.DeviceName = wDMSDeviceStatus.DeviceName;
        this.DeviceID = wDMSDeviceStatus.DeviceID;
        this.AssetNo = wDMSDeviceStatus.AssetNo;


        this.ModelID = wDMSDeviceStatus.ModelID;
        this.ModelNo = wDMSDeviceStatus.ModelNo;
        this.ModelName = wDMSDeviceStatus.ModelName;
        this.Remark = wDMSDeviceStatus.Remark;


        this.DeviceType = wDMSDeviceStatus.DeviceType;
        this.DeviceTypeCode = wDMSDeviceStatus.DeviceTypeCode;
        this.DeviceTypeName = wDMSDeviceStatus.DeviceTypeName;

        this.PositionText = wDMSDeviceStatus.PositionText;
        this.AreaID = wDMSDeviceStatus.AreaID;
        this.AreaNo = wDMSDeviceStatus.AreaNo;

        this.ImageIcon = wDMSDeviceStatus.ImageIcon;

        this.Status = wDMSDeviceStatus.Status;
        this.StatusTime = wDMSDeviceStatus.StatusTime;
        this.StatusHistory = wDMSDeviceStatus.StatusHistory;
        this.Duration = wDMSDeviceStatus.Duration;

    }

    @JsonProperty("DeviceNo")
    public String getDeviceNo() {
        return DeviceNo;
    }

    public void setDeviceNo(String deviceNo) {
        DeviceNo = deviceNo;
    }

    @JsonProperty("DeviceID")
    public int getDeviceID() {
        return DeviceID;
    }

    public void setDeviceID(int deviceID) {
        DeviceID = deviceID;
    }

    @JsonProperty("DeviceName")
    public String getDeviceName() {
        return DeviceName;
    }

    public void setDeviceName(String deviceName) {
        DeviceName = deviceName;
    }

    @JsonProperty("AssetNo")
    public String getAssetNo() {
        return AssetNo;
    }

    public void setAssetNo(String assetNo) {
        AssetNo = assetNo;
    }

    @JsonProperty("ModelID")
    public int getModelID() {
        return ModelID;
    }

    public void setModelID(int modelID) {
        ModelID = modelID;
    }

    @JsonProperty("ModelName")
    public String getModelName() {
        return ModelName;
    }

    public void setModelName(String modelName) {
        ModelName = modelName;
    }

    @JsonProperty("ModelNo")
    public String getModelNo() {
        return ModelNo;
    }

    public void setModelNo(String modelNo) {
        ModelNo = modelNo;
    }

    @JsonProperty("Remark")
    public String getRemark() {
        return Remark;
    }

    public void setRemark(String remark) {
        Remark = remark;
    }

    @JsonProperty("DeviceType")
    public int getDeviceType() {
        return DeviceType;
    }

    public void setDeviceType(int deviceType) {
        DeviceType = deviceType;
    }

    @JsonProperty("DeviceTypeName")
    public String getDeviceTypeName() {
        return DeviceTypeName;
    }

    public void setDeviceTypeName(String deviceTypeName) {
        DeviceTypeName = deviceTypeName;
    }

    @JsonProperty("DeviceTypeCode")
    public String getDeviceTypeCode() {
        return DeviceTypeCode;
    }

    public void setDeviceTypeCode(String deviceTypeCode) {
        DeviceTypeCode = deviceTypeCode;
    }

    @JsonProperty("AreaID")
    public int getAreaID() {
        return AreaID;
    }

    public void setAreaID(int areaID) {
        AreaID = areaID;
    }

    @JsonProperty("AreaNo")
    public String getAreaNo() {
        return AreaNo;
    }

    public void setAreaNo(String areaNo) {
        AreaNo = areaNo;
    }

    @JsonProperty("PositionText")
    public String getPositionText() {
        return PositionText;
    }

    public void setPositionText(String positionText) {
        PositionText = positionText;
    }

    @JsonProperty("ImageIcon")
    public String getImageIcon() {
        return ImageIcon;
    }

    public void setImageIcon(String imageIcon) {
        ImageIcon = imageIcon;
    }

    @JsonProperty("Status")
    public int getStatus() {
        return Status;
    }

    public void setStatus(int status) {
        Status = status;
    }

    @JsonProperty("StatusHistory")
    public int getStatusHistory() {
        return StatusHistory;
    }

    public void setStatusHistory(int statusHistory) {
        StatusHistory = statusHistory;
    }

    @JsonProperty("StatusTime")
    public Calendar getStatusTime() {
        return StatusTime;
    }

    public void setStatusTime(Calendar statusTime) {
        StatusTime = statusTime;
    }

    @JsonProperty("Duration")
    public int getDuration() {
        return Duration;
    }

    public void setDuration(int duration) {
        Duration = duration;
    }

    @JsonProperty("StatusDurationDic")
    public Map<String, Integer> getStatusDurationDic() {
        return StatusDurationDic;
    }

    public void setStatusDurationDic(Map<String, Integer> statusDurationDic) {
        StatusDurationDic = statusDurationDic;
    }

    @JsonProperty("StatusTimesDic")
    public Map<String, Integer> getStatusTimesDic() {
        return StatusTimesDic;
    }

    public void setStatusTimesDic(Map<String, Integer> statusTimesDic) {
        StatusTimesDic = statusTimesDic;
    }

    @JsonProperty("PlanDuration")
    public int getPlanDuration() {
        return PlanDuration;
    }

    public void setPlanDuration(int planDuration) {
        PlanDuration = planDuration;
    }

    @JsonProperty("FailTimes")
    public int getFailTimes() {
        if (StatusTimesDic != null && StatusTimesDic.containsKey((DMSDeviceStatusEnum.Alarm.getValue() + ""))) {
            return StatusTimesDic.get((DMSDeviceStatusEnum.Alarm.getValue() + ""));
        }
        return 0;
    }

    public void setFailTimes(int failTimes) {
        FailTimes = failTimes;
    }

    @JsonProperty("TurnOnDuration")
    public int getTurnOnDuration() {
        if (StatusDurationDic != null && StatusDurationDic.containsKey((DMSDeviceStatusEnum.TurnOn.getValue() + ""))) {
            return StatusDurationDic.get((DMSDeviceStatusEnum.TurnOn.getValue() + ""));
        }
        return 0;
    }

    public void setTurnOnDuration(int turnOnDuration) {
        TurnOnDuration = turnOnDuration;
    }

    @JsonProperty("TurnOffDuration")
    public int getTurnOffDuration() {
        if (StatusDurationDic != null && StatusDurationDic.containsKey("0")) {
            return StatusDurationDic.get("0");
        }
        return 0;
    }

    public void setTurnOffDuration(int turnOffDuration) {
        TurnOffDuration = turnOffDuration;
    }

    @JsonProperty("AlarmDuration")
    public int getAlarmDuration() {
        if (StatusDurationDic != null && StatusDurationDic.containsKey((DMSDeviceStatusEnum.Alarm.getValue() + ""))) {
            return StatusDurationDic.get((DMSDeviceStatusEnum.Alarm.getValue() + ""));
        }
        return 0;
    }

    public void setAlarmDuration(int alarmDuration) {
        AlarmDuration = alarmDuration;
    }

    @JsonProperty("MTTF")
    public int getMTTF() {
        return (TurnOnDuration < AlarmDuration) ? 0 : ((TurnOnDuration - AlarmDuration) / (FailTimes <= 0 ? 1 : FailTimes));
    }

    public void setMTTF(int MTTF) {
        this.MTTF = MTTF;
    }

    @JsonProperty("MTBF")
    public int getMTBF() {
        return TurnOnDuration / (FailTimes <= 0 ? 1 : FailTimes);
    }

    public void setMTBF(int MTBF) {
        this.MTBF = MTBF;
    }

    @JsonProperty("MTTR")
    public int getMTTR() {
        return AlarmDuration / (FailTimes <= 0 ? 1 : FailTimes);
    }

    public void setMTTR(int MTTR) {
        this.MTTR = MTTR;
    }

    @JsonProperty("RepairCount")
    public int getRepairCount() {
        return RepairCount;
    }

    public void setRepairCount(int repairCount) {
        RepairCount = repairCount;
    }

    @JsonProperty("MaintainCount")
    public int getMaintainCount() {
        return MaintainCount;
    }

    public void setMaintainCount(int maintainCount) {
        MaintainCount = maintainCount;
    }

    @JsonProperty("RepairDuration")
    public double getRepairDuration() {
        return RepairDuration;
    }

    public void setRepairDuration(double repairDuration) {
        RepairDuration = repairDuration;
    }

    @JsonProperty("MaintainDuration")
    public double getMaintainDuration() {
        return MaintainDuration;
    }

    public void setMaintainDuration(double maintainDuration) {
        MaintainDuration = maintainDuration;
    }


}
